<template>
  <el-dialog :visible.sync="visible" v-dialogDrag :title="title" :close-on-click-modal="false" class="tl-dialog" width="1200px" @open="open" @close="close">
	<el-button type="text" @click="addSensitive" style="margin-right:20px" size="medium"><i class="el-icon-circle-plus-outline"></i>新增敏感词</el-button>
    <el-form class="tl-form" ref="form" :model="model" :rules="rules" label-width="150px" :disabled="disableEditSubmit">
			<el-row v-for="(item, index) in model.sensitiveList" :key="index + 'ourproduct'">
				<el-col :span="14">
					<el-form-item label="敏感词" :prop="'sensitiveList.' + index + '.word'" :rules="rules.validateRequire">
						<el-input v-model="item.word"></el-input>
					</el-form-item>
				</el-col>
				<el-col :span="7">
					<el-form-item label="有效" prop="enabled">
						<el-radio-group v-model="item.enabled">
							<el-radio :label="parseInt(item.code)" v-for="item in codeModel.enabledList" :key="item.code">{{ item.name }}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
				<el-col :span="3">
					<el-form-item label="" label-width="10px">
						<el-button type="text" size="medium" @click="removeSensitive(item, index)"><i class="el-icon-remove-outline"></i>删除</el-button>
					</el-form-item>
				</el-col>
			</el-row>
			<!-- <el-row>
				<el-col :span="12">
					<el-form-item label="类型" prop="type" :rules="rules.validateRequire">
						<el-select v-model="model.type" filterable clearable>
							<el-option v-for="item in codeModel.typeList" :key="item.code" :label="item.name" :value="item.code" />
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="12">
					<el-form-item label="适用范围" prop="rangesys" :rules="rules.validateRequire">
						<el-select v-model="model.rangesys" filterable clearable>
							<el-option v-for="item in codeModel.rangesysList" :key="item.code" :label="item.name" :value="item.code" />
						</el-select>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="12">
					<el-form-item label="有效" prop="enabled">
						<el-radio-group v-model="model.enabled">
							<el-radio :label="parseInt(item.code)" v-for="item in codeModel.enabledList" :key="item.code">{{ item.name }}</el-radio>
						</el-radio-group>
					</el-form-item>
				</el-col>
			</el-row>
			<el-row>
				<el-col :span="24">
					<el-form-item label="提示：" prop="enabled">
						<span>过滤词用于过滤包含敏感词的词汇，例如敏感词为“敏感”，过滤词为“过滤敏感”，则录入“过滤敏感”不会被拦截。</span>
					</el-form-item>
				</el-col>
			</el-row> -->
    </el-form>
    <div slot="footer" class="dialog-footer">
      <el-button :type="disableEditSubmit === false ? 'text' : 'primary'" @click="doCancelEdit">取消</el-button>
      <el-button type="primary" @click="doSubmitEdit" :loading="saveLoading" v-if="disableEditSubmit === false">确认</el-button>
    </div>
  </el-dialog>
</template>

<script>
/** mixins */
import { mixin_edit } from '@tapui/mixins/mixin_edit'
/** 子组件 */
/** 工具类 */
import { putAction, getAction, postAction, deleteAction } from '@tapui/utils/http'
/** VUE配置 */
export default {
  mixins: [mixin_edit],
  components: { },
  data() {
    return {
      moduleTitle: '敏感词库',
      urlPrefix: '/mms/sensitiveThesaurus/',
      url: {
        // 额外的url
		add: '/mms/sensitiveThesaurus/doSave',
        edit: '/mms/sensitiveThesaurus/doSave'
      }
    }
  },
  methods: {
    loaded() {
      // 页面加载完毕执行
    //   if (this.isAdd) {
    //     this.$set(this.model, 'type', '1')
    //     this.$set(this.model, 'rangesys', '1')
    //   }
    },
	assignDefaultValue() {
      if (this.isAdd) {
        this.$set(this.model, 'sensitiveList', [])
		this.model.sensitiveList.push({
        type: '1',
        rangesys: '1',
		enabled: 1
      })
      }
    },
	addSensitive() {
      this.model.sensitiveList.push({
        type: '1',
        rangesys: '1',
		enabled: 1
      })
    },
	removeSensitive(item, index) {
      const that = this
      if (that.model.sensitiveList.length <= 1) {
        this.$tap.alert('不允许删除！', 'warning')
        return
      }
      that.model.sensitiveList.splice(index, 1)
    },
	doAdd() {
      this.saveLoading = true
      postAction(this.url.add, this.model)
        .then(res => {
          if (res.success) {
            this.$tap.message('添加成功', 'success')
			this.saveLoading = false
			this.visible = false
			this.$parent.loadData()
          } else {
            this.$tap.alert(res.message, 'warning')
            this.saveLoading = false
          }
        })
        .catch(err => {
          this.saveLoading = false
        })
    }
  }
}
</script>

